<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Articel extends BaseModel {

	protected $table = 'articel';

	public $timestamps = false;

	protected $fillable = [
		'title',
		'content',
		'add_time',
		'author',
		'status',
		'cat_id'
	];

	public function scopeStatus($query){
		return $query->where('status',self::NORMAL_STATUS);
	}

	public function get_articels(){
		return $this
			->status()
			->orderBy('is_recommend','desc')
			->paginate(self::PAGESIZE);
	}

	public function get_articel_detail($id){
		return $this
			->status()
			->find($id);
	}

	public function get_recommend_articel(){
		return $this
			->status()
			->where('is_recommend',self::NORMAL_STATUS)
			->paginate(self::PAGESIZE);
	}

	public function get_articel_by_id($id){
		return $this
			->status()
			->where('cat_id',$id)
			->orderBy('add_time','desc')
			->paginate(2);
	}
}
